from django import forms
from .models import Author, Book, BookRating, BookReview

class AuthorForm(forms.ModelForm):
    class Meta:
        model = Author
        fields = ['first_name', 'last_name', 'date_of_birth', 'date_of_death', 'avatar', 'intro']
        widgets = {
            'date_of_birth': forms.DateInput(attrs={'type': 'date'}),
            'date_of_death': forms.DateInput(attrs={'type': 'date'}),
            'intro': forms.Textarea(attrs={'rows': 4, 'placeholder': '请输入作者简介...'}),
        }

class BookForm(forms.ModelForm):
    class Meta:
        model = Book
        fields = ['title', 'author', 'summary', 'isbn', 'cover', 'category', 'tags', 'buy_link']
        widgets = {
            'summary': forms.Textarea(attrs={'rows': 4, 'placeholder': '请输入书籍简介...'}),
            'tags': forms.TextInput(attrs={'placeholder': '多个标签用逗号分隔'}),
            'category': forms.TextInput(attrs={'placeholder': '如：文学、科幻、历史...'}),
            'buy_link': forms.URLInput(attrs={'placeholder': '可选，填写电商购买链接'}),
        }

class BookRatingForm(forms.ModelForm):
    class Meta:
        model = BookRating
        fields = ['score']
        widgets = {
            'score': forms.RadioSelect(choices=[(i, f'{i}星') for i in range(1, 6)])
        }

class BookReviewForm(forms.ModelForm):
    class Meta:
        model = BookReview
        fields = ['content']
        widgets = {
            'content': forms.Textarea(attrs={'rows': 3, 'placeholder': '写下你的评论...'}),
        } 